using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using System.Windows.Forms;

namespace IngenEngine
{
	internal class CameraInformation
	{
		private float fieldOfView;
		private float aspectRatio;
		private float frustumNearPlane;
		private float frustumFarPlane;
		private Vector3 location;
		private Vector3 target;
		private Vector3 upDirection;

		#region Properties
		public float FieldOfView
		{
			get { return fieldOfView; }
			set { fieldOfView = value; }
		}

		public float AspectRatio
		{
			get { return aspectRatio; }
			set { aspectRatio = value; }
		}

		public float FrustumNearPlane
		{
			get { return frustumNearPlane; }
			set { frustumNearPlane = value; }
		}

		public float FrustumFarPlane
		{
			get { return frustumFarPlane; }
			set { frustumFarPlane = value; }
		}


		public Vector3 Location
		{
			get { return location; }
			set { location = value; }
		}

		public Vector3 Target
		{
			get { return target; }
			set { target = value; }
		}


		public Vector3 UpDirection
		{
			get { return upDirection; }
			set { upDirection = value; }
		} 
		#endregion
	}
	
	internal class Camera
	{
		public Camera(ref Device device)
		{
			SetDrawDistance(ref device);
			SetPosition(ref device);
		}
		public Device SetDrawDistance(ref Device device, CameraInformation info)
		{
			//Frustum of scene
			//This sets the draw distance of what the camera sees.
			int width = device.CreationParameters.FocusWindow.Width;
			int height = device.CreationParameters.FocusWindow.Height;

			device.Transform.Projection =
				Matrix.PerspectiveFovLH(
					(float)Math.PI / 4,	//Field of view
					width / height,		//Aspect Ratio (width/height of the screen resolution
					1,					//Beginning of the frustum
					200);				//End of the frustum (draw distance)
			return device;
		}

		public Device SetPosition(ref Device device, CameraInformation info)
		{
			//Set the camera's position in the universe, where to look at, and it's position in terms of height
			device.Transform.View =
				Matrix.LookAtLH(new Vector3(0, 0, 10),	//Location of the camera
								new Vector3(0, 0, 0),	//Target of camera (orientation)
								new Vector3(0, 1, 0));	//Which direction is up (usually 0,1,0)
			return device;
		}
	}
}
